<?php


namespace app\adminapi\dao\hotel;


use app\common\dao\BaseHotelDao;
use app\common\model\hotel\Hotel;

/**
 * @projectName src
 */
class HotelDao extends BaseHotelDao
{
    public static function add(array $params)
    {
        Hotel::create([
            'pid' => $params['pid'] ?? 0,
            'hotel_name' => $params['hotel_name'],
            'hotel_scale' => $params['hotel_scale'] ?? '',
            'hotel_nature' => $params['hotel_nature'] ?? '',
            'firm_name' => $params['firm_name'],
            'contact_person' => $params['contact_person'],
            'contact_phone' => $params['contact_phone'],
            'status'=>$params['status'] ?? 0
        ]);
    }

    public static function edit(array $params): bool
    {
        try {
            Hotel::update($params);
            return true;
        } catch (\Exception $e) {
            self::setError($e->getMessage());
            return false;
        }
    }

    public static function delete(array $params)
    {
        Hotel::destroy($params['id']);
    }

    public static function detail(array $params): array
    {
        return Hotel::findOrEmpty($params['id'])->toArray();
    }

    public static function getAllData()
    {
        return Hotel::order('id', 'desc')->select()->toArray();
    }
}